#include "Environment.h"

Environment::Environment(Graphics ** gr,int x, int y)
{
	screenx = x;
	screeny = y;
	GR = gr;
	Elements.push_back(new env_element(gr));
	scrollx = 0;
	scrolly = 0;
};

void Environment::draw_elements(ALLEGRO_DISPLAY ** display)
{
	Elements[0]->draw(display,&scrollx,&scrolly);
}

void Environment::draw_background(ALLEGRO_DISPLAY ** display)
{
	al_draw_bitmap(GR[0]->get_bmp(2,0),-scrollx/2,-scrolly/2,0);
}

void Environment::scroll(int x, int y)
{
	if(-scrollx + x + SCROLLDIST > screenx)
	{
		int buffer = (-scrollx + x + SCROLLDIST) - screenx;
		scrollx += buffer;
	}
	else if(-scrollx + x - SCROLLDIST < 0)
	{
		int buffer = -(-scrollx + x - SCROLLDIST);
		scrollx -= buffer;
	}
	if(-scrolly + y + SCROLLDIST > screeny)
	{
		int buffer = (-scrolly + y + SCROLLDIST) - screeny;
		scrolly += buffer;
	}
	else if(-scrolly + y - SCROLLDIST < 0)
	{
		int buffer = -(-scrolly + y - SCROLLDIST);
		scrolly -= buffer;
	}
}

int Environment::get_scrollx()
{
	return scrollx;
}

int Environment::get_scrolly()
{
	return scrolly;
}

int * Environment::get_pscrollx()
{
	return &scrollx;
}

int * Environment::get_pscrolly()
{
	return &scrolly;
}

env_element ** Environment::get_element(int index)
{
	return &(Elements[index]);
}

void Environment::create_new_env(int x)
{
	Elements[0]->create_new_env(x);
}

Environment::~Environment()
{

}